<template>
  <div>
    <!-- 
    <el-form :model="user" ref="loginForm" label-width="100px" class="demo-dynamic">
      <el-row>
        <el-col :offset="6" :span="6">
          <el-form-item prop="uname" label="用户名" :rules="[
            { required: true, message: '请输入用户名', trigger: 'blur'}
          ]">
            <el-input v-model="user.uname"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :offset="6" :span="6">
          <el-form-item prop="upwd" label="密码" :rules="[
              { required: true, message: '请输入密码', trigger: 'blur'}
            ]">
            <el-input type="password" v-model="user.upwd"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :offset="6" :span="6">
          <el-form-item>
            <el-button type="primary" @click="submitForm('loginForm')">提交</el-button>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
  -->

    <el-form :model="user" :rules="rules" ref="loginForm" label-position="left" label-width="0px" class="demo-ruleForm login-container">
      <h3 class="title">黑马买买买---商城管理系统</h3>
      <el-form-item prop="uname">
        <el-input type="text" v-model="user.uname" auto-complete="off" placeholder="账号"></el-input>
      </el-form-item>
      <el-form-item prop="upwd">
        <el-input type="password" v-model="user.upwd" auto-complete="off" placeholder="密码"></el-input>
      </el-form-item>
      <el-checkbox checked class="remember">记住密码</el-checkbox>
      <el-form-item style="width:100%;">
        <el-button style="width:100%;" type="primary" @click="submitForm('loginForm')">提交</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>

<style lang="scss" scoped>
  .login-container {
    /*box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);*/
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
    .title {
      margin: 0px auto 40px auto;
      text-align: center;
      color: #505458;
    }
    .remember {
      margin: 0px 0px 35px 0px;
    }
  }
</style>

<script>
  export default {
    data() {
      return {
        user: {
          uname: "",
          upwd: ""
        }, 
        rules: {
          uname: [
            { required: true, message: '请输入用户名', trigger: 'blur' }
          ],
          upwd: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$axios.post('admin/account/login', this.user).then(response => {
              if (response.data.status == 1) {
                this.$message.error(response.data.message)
                return
              }

              this.$router.push({ name: "goodslist" })
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
    }
  }
</script>